package com.ruoyi.web.core.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

import java.net.Inet4Address;
import java.net.UnknownHostException;

@Configuration
@Slf4j
public class SwaggerPrint implements ApplicationListener<WebServerInitializedEvent> {


    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        try {
            String hostAddress = Inet4Address.getLocalHost().getHostAddress();
            int port = event.getWebServer().getPort();
            String app = event.getApplicationContext().getApplicationName();
            log.info("访问地址： http://"+hostAddress+":"+port+app+"/doc.html");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
